<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-16 20:57:19
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-03-01 02:43:18
 * ------------------------------------------------ *
 * 用户管理                                         *
 * ------------------------------------------------ */

namespace Admin\Controller;
class UsersController extends CommonController {

// 分页查询

	public function index(){
		if(IS_AJAX){
			switch(I('ajax')){
				case "checkKey":
					$key = I('key');
				 	$id = I('id',0);
					$status = D('Users')->checkLoginKey($key,$id);
					$this->ajaxReturn($status);
					break;				
				case "userStatus":
					$status = D('Users')->editUserStatus();
					$this->ajaxReturn($status);
					break;
				case "delUsers":
				
					$status = D('Users')->delUsers();
					$this->ajaxReturn($status);
			}
		}

		if(I('noAjax')=="editUsers"){
			if(I('id',0)>0){
				$m = D('Users')->editUsers();
				//echo "<script>parent.callback('".$m."',0)</script>";return;
				if($m){
					
					echo "<script>parent.callback('用户修改成功！',1)</script>";
					return;
				}		
				echo "<script>parent.callback('用户修改失败！',0)</script>";
				return;
			}else{
				$m = D('Users')->addUsers();

				if($m){
					
					echo "<script>parent.callback('用户添加成功！',1)</script>";
					return;
				}		
				echo "<script>parent.callback('用户添加失败！',0)</script>";
				return;
			}
		}
		
		$m = D('Users');
    	$PQ = $m->getUsers();
    	$pageSize=(int)I('pageSize',0);
    	if($pageSize>0) $PQ['pageSize']=$pageSize;
    	$page= getPage($PQ['total'],$PQ['pageSize']);
    	$PQ['page'] = $page->show();
    	$this->assign('PQ',$PQ);
    	$this->assign('loginName',I('loginName'));
    	$this->assign('userPhone',I('userPhone'));
    	$this->assign('userEmail',I('userEmail'));
    	$this->assign('userType',I('userType',-1));
        $this->display();
	}



// 新增/编辑页面

	public function edit(){
    	if(I('id',0)>0){  		
    		$object =D('Users')->get();
    		$this->assign('object',$object);		    
    	}
    	$this->display();    	
	}

}